<script setup>
    import * as echarts from 'echarts'
    import {onMounted} from "vue";
    import {ref} from "vue";
    import chartApi from "@/api/chart.js";

    const chartRef = ref()
    onMounted(() => {
        const myChart = echarts.init(chartRef.value);
        chartApi.selectCategoryCount().then((result) => {
            if (result.code === 0) {
                const option = {
                    title: {
                        text: '药品分类统计',
                        left: 'center'
                    },
                    xAxis: {
                        type: 'category',
                        data: result.data.name
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            data: result.data.value,
                            type: 'bar'
                        }
                    ]
                };

                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
            }
        })
    })
</script>

<template>
    <div ref="chartRef" style="width: 100%;height: 100%"></div>
</template>

<style scoped>

</style>